//
//  SAWRefreTableView.m
//  BestLearning
//
//  Created by edz on 2018/1/31.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "CorrectModel.h"
#import "AppDelegate.h"

#import "SAWCorrecTabCell.h"
#import "SAWRefreTableView.h"
@interface SAWRefreTableView()<UITableViewDelegate,UITableViewDataSource>

@end
@implementation SAWRefreTableView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       [self setUI];
    }
   
    return self;
}
-(void )setSAWDataArr:(NSArray *)SAWDataArr
{
    _SAWDataArr = SAWDataArr;
    
    [_SAWTabView reloadData];
    [_SAWTabView.mj_footer endRefreshing];
    [_SAWTabView.mj_header endRefreshing];
}
-(void)setUI
{
    _SAWTabView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-kTopHeight)];
    [self addSubview:_SAWTabView];
    _SAWTabView.backgroundColor = RGBColor(245, 245, 245);
    [_SAWTabView registerClass:[SAWCorrecTabCell class] forCellReuseIdentifier:@"Cell"];
    _SAWTabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _SAWTabView.rowHeight=50;
    _SAWTabView.delegate=self;
    _SAWTabView.dataSource=self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _SAWDataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SAWCorrecTabCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    CorrectModel *model = _SAWDataArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lab.text=model.name;
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CorrectModel *model = _SAWDataArr[indexPath.row];
    if ([model.categoryName isEqualToString:@"文化类"]) {
        
        if (self.pushVC) {
            
            self.pushVC(model.ID, YES);
        }
       
       
    }
    else
    {
        if (self.pushVC) {
            
            self.pushVC(model.ID, NO);
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
